#include"process_pool.h"
int make_child(process_data_t* p_manage,int process_num)
{
    int i;
    pid_t pid;
    int fds[2];
    int ret;
    for(i=0;i<process_num;i++)
    {
        ret=socketpair(AF_LOCAL,SOCK_STREAM,0,fds);
        ERROR_CHECK(ret,-1,"socktpair")
        pid=fork();
        if(0==pid)
        {
            close(fds[1]);
            child_handle(fds[0]);
        }
        close(fds[0]);
        p_manage[i].pid=pid;
        p_manage[i].fd=fds[1];
        p_manage[i].busy=0;
        
    
    #ifdef DEBUG
        printf("p_manage[%d].fd=%d\n",i,p_manage[i].fd);
#endif
    }
    // wait(NULL);
}
int child_handle(int fd)
{
    int new_fd,ret,exit_flag;
    char flag=1;
    
    
    while (1)
    {
        recv_fd(fd,&new_fd,&exit_flag);
        if(exit_flag)
        {
            printf("child %d will exit\n",getpid());
            exit(0);
        }
        printf("gets task,new_fd=%d\n",new_fd);
        tran_file(new_fd);
        // close(new_fd);
        write(fd,&flag,sizeof(flag));
    }
    
}